<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>EJS Demo Page</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .user-card {
            border: 1px solid #ddd;
            border-radius: 8px;
            padding: 16px;
            margin: 16px 0;
            background-color: #f9f9f9;
        }
        .article-card {
            border: 1px solid #ccc;
            border-radius: 8px;
            padding: 16px;
            margin: 16px 0;
            background-color: #fff;
        }
        .highlight {
            background-color: yellow;
            padding: 2px 4px;
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <h1>EJS Demo Page</h1>
    
    <h2>显示单个值</h2>
    <p>欢迎来到 <span class="highlight"><%= title %></span>!</p>
    
    <h2>条件渲染</h2>
    <% if (showMessage) { %>
        <p class="highlight">这是一条特殊消息！</p>
    <% } else { %>
        <p>没有消息显示。</p>
    <% } %>
    
    <h2>循环渲染列表</h2>
    <ul>
        <% items.forEach(function(item) { %>
            <li class="highlight"><%= item.name %></li>
        <% }); %>
    </ul>
    
    <h2>用户列表</h2>
    <% users.forEach(function(user) { %>
        <div class="user-card">
            <h3><%= user.name %> (ID: <%= user.id %>)</h3>
            <p>Email: <%= user.email %></p>
            <p>角色: <span class="highlight"><%= user.role %></span></p>
        </div>
    <% }); %>
    
    <h2>文章列表（来自数据库）</h2>
    <% if (articles && articles.length > 0) { %>
        <% articles.forEach(function(article) { %>
            <div class="article-card">
                <h3><%= article.title %></h3>
                <p><%= article.content %></p>
                <small>创建时间: <%= article.createdAt %></small>
            </div>
        <% }); %>
    <% } else { %>
        <p>暂无文章</p>
    <% } %>
</body>
</html>